package com.miaosha.redis.list;

import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @author lsq
 * @create 2021-10-16 11:34
 * @description
 * @menu
 **/
public class TodoDemo {

    private Jedis jedis = new Jedis("182.42.113.98", 6379);


    /**
     * 添加待办事项
     *
     * @param userId
     * @param todoEvent
     */
    public void addTodoEvent(Long userId, String todoEvent) {
        jedis.lpush("tdo_event::" + userId, todoEvent);
    }

    /**
     * 分页查询待办信息
     *
     * @param userId
     * @param pageNo
     * @param pageSize
     * @return
     */
    public List<String> findTodoEventByPage(long userId, int pageNo, int pageSize) {

        int startIndex = (pageNo - 1) * pageSize;
        int endIndex = pageNo * pageSize - 1;
        return jedis.lrange("todo_event::" + userId, startIndex, endIndex);
    }
}
